<?php
namespace Model;

use Illuminate\Database\Capsule\Manager as DB;
use Library\Log;


/**
 * Cnf
 * @author los_gsy
 */
class Cnf extends Base {
	/**
	 * 构造函数
	 */
	public function __construct() {
		parent::__construct();
	}


	/**
	 * test
	 */
	static public function test() {
// 		return __METHOD__;
		return parent::getTableName();
	}


	/**
	 * 通过类型，查询配置
	 * @param string $type
	 */
	static public function getCnfListByType($type) {
		$result = DB::table(self::getTableName())
			->where('type', $type)
			->get();
		Log::debug(__METHOD__ . ': $result = ' . var_export($result, true));
		return $result;
	}


	/**
	 * 通过类型和键，查询配置项
	 * @param string $type
	 * @param string $k
	 */
	static public function getCnfByTypeAndK($type, $k) {
		$result = DB::table(self::getTableName())
			->where('type', $type)
			->where('k', $k)
			->first();
		Log::debug(__METHOD__ . ': $result = ' . var_export($result, true));
		return $result;
	}


	/**
	 * 修改单个配置时，验证重复配置项
	 * @param string $type
	 * @param string $k
	 * @param int $id
	 * @return array
	 */
	static public function findSameEditCnf($type, $k, $id) {
		$result = DB::table(self::getTableName())
			->where('type', $type)
			->where('k', $k)
			->where('id', $id, '!=')
			->first();
		Log::debug(__METHOD__ . ': $result = ' . var_export($result, true));
		return $result;
	}





}